 
import { State } from "framework/FSM/AState";
import { ActionArgHelper } from "../../../ActionManager/ActionArgHelper";
import { PositionHelper } from "utils/position/PositionHelper";

 



/**
 * 填充ext的闲暇工作
 */ 
 /*@profile*/
export class CombatBehavior<T extends IStateArg<Creep>>  extends State<T>
{
    /**
     * 搬运工行为,先做简化行为。运输的两端都有container
     * @param arg 
     */
    public  getActions(arg:T):Action[]
    {
        // global.Log.Info(`${arg.entity.name}`);
        const creep = arg.entity;
      
        const hurts = creep.room.getHurtCreeps();
        if(creep.room.controller?.my)
        {
            if( hurts.length && creep.memory.body[HEAL])
            {
                creep.healAroundCreep();
            }
            // 在自己的房间就不治疗了浪费cpu
            return []
        }
        if( hurts.length && creep.memory.body[HEAL])
        {
            creep.healAroundCreep();
         
            
            return [ActionArgHelper.actionMoveto(creep,{pos:hurts[0].pos,range:1},{})]
        }
     
        // 判断是否有敌人，没有则选择一个矿附近驻扎
        if(!creep.memory.targetId)
        {
            const source = creep.room.getSource();
            if(source.length>0)
            {
                creep.memory.targetId = source[0].id;
            }
            
        }
        const source = Game.getObjectById(creep.memory.targetId as Id<Source>);
        if(source  )
        {
            const hostileCreeps = source.pos.lookForInRange(LOOK_CREEPS,5).filter(e=>!e.creep.my);
            if(hostileCreeps.length>0)
            {
                
                creep.setTactic({goal:undefined,type:2,targets:[PositionHelper.getObjectRef(hostileCreeps[0].creep)]});
                creep.setAroundHostileCreeps(hostileCreeps.map(e=>e.creep));
            }
            else
            {
                return [ActionArgHelper.actionMoveto(creep,{pos:source.pos,range:5},{})]
            }
        }
        
        
        return []

    }
}
